﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using SqlCon;

namespace yfxt
{
    public partial class cx_ypxxcx : Form
    {
        public cx_ypxxcx()
        {
            InitializeComponent();
        }

        public string s_temp;

        public string S_temp
        {
            get { return s_temp; }
            set { this.s_temp = value; }
        }

        public string s_temp_01;

        public string S_temp_01
        {
            get { return s_temp_01; }
            set { this.s_temp_01 = value; }
        }




        SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction);
        private void cx_ypxxcx_Load(object sender, EventArgs e)
        {
            if (conn.State != ConnectionState.Open) { conn.Open(); }

            string s = "select pydm,ypmc,ypgg,ypdw,ypxh from yk_typk where pydm like '" + textBox1.Text.ToString() + "%' ";

            using (SqlDataAdapter da = new SqlDataAdapter(s, conn))
            {

                DataTable dt = new DataTable();

                da.Fill(dt);

                dataGridView1.DataSource = dt;
            }

            dataGridView1.Columns[0].HeaderCell.Value = "拼音代码";
            dataGridView1.Columns[1].HeaderCell.Value = "药品名称";
            dataGridView1.Columns[2].HeaderCell.Value = "药品规格";
            dataGridView1.Columns[3].HeaderCell.Value = "药品单位";
            dataGridView1.Columns[4].HeaderCell.Value = "药库编码";

            comboBox1.Items.Add("全部");
            comboBox1.Items.Add("西药");
            comboBox1.Items.Add("中成药");
            comboBox1.Items.Add("中草药");

            comboBox1.Text = "全部";


        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            string s_01;

            if (conn.State != ConnectionState.Open) { conn.Open(); }

            DataTable dt = new DataTable();

            if (comboBox1.Text.ToString().Equals("全部"))//全部药品
            {
                s_01 = "select pydm,ypmc,ypgg,ypdw,ypxh from yk_typk where  pydm like '" + textBox1.Text.ToString() + "%' ";

                using (SqlDataAdapter da = new SqlDataAdapter(s_01, conn))
                {
                    da.Fill(dt);

                    dataGridView1.DataSource = dt;
                }

            }
            else if (comboBox1.Text.ToString().Equals("西药")) //西药
            {
                s_01 = "select pydm,ypmc,ypgg,ypdw,ypxh from yk_typk where zblb=1 and pydm like '" + textBox1.Text.ToString() + "%' ";

                using (SqlDataAdapter da = new SqlDataAdapter(s_01, conn))
                {
                    da.Fill(dt);

                    dataGridView1.DataSource = dt;
                }

            }
            else if (comboBox1.Text.ToString().Equals("中成药"))//中成药
            {
                s_01 = "select pydm,ypmc,ypgg,ypdw,ypxh from yk_typk where  zblb=2 and pydm like '" + textBox1.Text.ToString() + "%' ";

                using (SqlDataAdapter da = new SqlDataAdapter(s_01, conn))
                {
                    da.Fill(dt);

                    dataGridView1.DataSource = dt;
                }

            }
            else if (comboBox1.Text.ToString().Equals("中草药"))//中草药
            {
                s_01 = "select pydm,ypmc,ypgg,ypdw,ypxh from yk_typk where  zblb=3 and pydm like '" + textBox1.Text.ToString() + "%' ";

                using (SqlDataAdapter da = new SqlDataAdapter(s_01, conn))
                {
                    da.Fill(dt);

                    dataGridView1.DataSource = dt;
                }

            }




            dataGridView1.Columns[0].HeaderCell.Value = "拼音代码";
            dataGridView1.Columns[1].HeaderCell.Value = "药品名称";
            dataGridView1.Columns[2].HeaderCell.Value = "药品规格";
            dataGridView1.Columns[3].HeaderCell.Value = "药品单位";
            dataGridView1.Columns[4].HeaderCell.Value = "药库编码";


            


        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlHelper.s= dataGridView1.CurrentRow.Cells["ypxh"].Value.ToString();

            cx_ypxxcx_xg ypxx = new cx_ypxxcx_xg();

            ypxx.Owner = this;

            ypxx.Show();

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {


            string s_01;

            if (conn.State != ConnectionState.Open) { conn.Open(); }

            DataTable dt = new DataTable();

            if (comboBox1.Text.ToString().Equals("全部"))//全部药品
            {
                s_01 = "select pydm,ypmc,ypgg,ypdw,ypxh from yk_typk where  pydm like '" + textBox1.Text.ToString() + "%' ";

                using (SqlDataAdapter da = new SqlDataAdapter(s_01, conn))
                {
                    da.Fill(dt);

                    dataGridView1.DataSource = dt;
                }

            }
            else if (comboBox1.Text.ToString().Equals("西药")) //西药
            {
                s_01 = "select pydm,ypmc,ypgg,ypdw,ypxh from yk_typk where zblb=1 and pydm like '" + textBox1.Text.ToString() + "%' ";

                using (SqlDataAdapter da = new SqlDataAdapter(s_01, conn))
                {
                    da.Fill(dt);

                    dataGridView1.DataSource = dt;
                }

            }
            else if (comboBox1.Text.ToString().Equals("中成药"))//中成药
            {
                s_01 = "select pydm,ypmc,ypgg,ypdw,ypxh from yk_typk where  zblb=2 and pydm like '" + textBox1.Text.ToString() + "%' ";

                using (SqlDataAdapter da = new SqlDataAdapter(s_01, conn))
                {
                    da.Fill(dt);

                    dataGridView1.DataSource = dt;
                }

            }
            else if (comboBox1.Text.ToString().Equals("中草药"))//中草药
            {
                s_01 = "select pydm,ypmc,ypgg,ypdw,ypxh from yk_typk where  zblb=3 and pydm like '" + textBox1.Text.ToString() + "%' ";

                using (SqlDataAdapter da = new SqlDataAdapter(s_01, conn))
                {
                    da.Fill(dt);

                    dataGridView1.DataSource = dt;
                }

            }




            dataGridView1.Columns[0].HeaderCell.Value = "拼音代码";
            dataGridView1.Columns[1].HeaderCell.Value = "药品名称";
            dataGridView1.Columns[2].HeaderCell.Value = "药品规格";
            dataGridView1.Columns[3].HeaderCell.Value = "药品单位";
            dataGridView1.Columns[4].HeaderCell.Value = "药库编码";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            SqlConnection conn_01 = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction);

            if (conn_01.State != ConnectionState.Open) { conn_01.Open(); }

            string s_01 = "select pydm,ypmc,ypgg,ypdw,ypxh from yk_typk where  pydm like '" + textBox1.Text.ToString().Trim() + "%' ";

            using (SqlDataAdapter da = new SqlDataAdapter(s_01, conn_01))
            {
                DataTable dt = new DataTable();

                da.Fill(dt);

                dataGridView1.DataSource = dt;
            }
            dataGridView1.Columns[0].HeaderCell.Value = "拼音代码";
            dataGridView1.Columns[1].HeaderCell.Value = "药品名称";
            dataGridView1.Columns[2].HeaderCell.Value = "药品规格";
            dataGridView1.Columns[3].HeaderCell.Value = "药品单位";
            dataGridView1.Columns[4].HeaderCell.Value = "药库编码";

            comboBox1.Text = "全部";
            textBox1.Text = "";
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {

            s_temp = dataGridView1.CurrentRow.Cells["ypxh"].Value.ToString();
            cx_ypxxcx_xg xg = new cx_ypxxcx_xg();

            xg.Owner = this;

            xg.Show();

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }
    }
}
